#ifndef _FPGA_PRIVATE_H_
#define _FPGA_PRIVATE_H_

#include "fpga_data_build.h"
#include "printl.h"

#define INIT_ENV         (101)
#define INIT_BSP         (102)
#define INIT_THREAD      (103)

#define MIN_RX_PACK_SIZE (38)  // debug
extern const char *dev_desc;
#define MAGIC_FPGA_IF "im_fpga_if"
extern char *pmagic;

#if defined(CONFIG_USE_DEBUG_ENV)
#define ENV_PRINT_E(fmt, ...)                              \
    if (env_print_e) {                                     \
	_ctstprint(C_ERROR, C_NORMAL, fmt, ##__VA_ARGS__); \
    }
#define ENV_PRINT_W(fmt, ...)                             \
    if (env_print_w) {                                    \
	_ctstprint(C_WARN, C_NORMAL, fmt, ##__VA_ARGS__); \
    }
#else
#define ENV_PRINT_E(fmt, ...)
#define ENV_PRINT_W(fmt, ...)
#endif


// 小端
#if 1
// 原来使用这串宏，用在arm上没问题，用在mips数据错误
//#define _STREAM_TO_32(data) (((data)[0] << 0) | ((data)[1] << 8) | ((data)[2]
//<< 16) | ((data)[3] << 24)) #define _STREAM_TO_16(data) (((data)[0] << 0) |
//((data)[1] << 8))

// mips
#define _STREAM_TO_32(data)                                   \
    (0xffffffff &                                             \
     ((((data)[0] & 0xff) << 0) | (((data)[1] & 0xff) << 8) | \
      (((data)[2] & 0xff) << 16) | (((data)[3] & 0xff) << 24)))
#define _STREAM_TO_16(data) \
    (0xffff & ((((data)[0] & 0xff) << 0) | (((data)[1] & 0xff) << 8)))

// #define _STREAM_TO_32(data)                                   \
// 	(((((data)[0] & 0xff) << 0) | (((data)[1] & 0xff) << 8) | \
// 	  (((data)[2] & 0xff) << 16) | (((data)[3] & 0xff) << 24)))
// #define _STREAM_TO_16(data) \
// 	(((((data)[0] & 0xff) << 0) | (((data)[1] & 0xff) << 8)))
#else
#endif


extern char *env_interface;

extern int env_future_show;
extern int env_otdr_dbg_level;
extern int env_print_otdr_data;
extern int env_dbg_tx;
extern int env_dbg_rx;
extern int env_dbg_bit_otdr_data;
extern int env_print_e;
extern int env_print_w;
extern int env_lowpower_thread;
extern int env_unuse_cksum;
extern int env_speed;


extern int rm_cp_fpga_ocid_sensitive(struct fpga_dev *dev, int sensitive);
#define PRINT_FUTURE(fmt, ...)                            \
    if (env_future_show) {                                \
	_ctstprint(C_WARN, C_NORMAL, fmt, ##__VA_ARGS__); \
    }
#endif